		var retentDayArray=[];
          var editIndex = undefined;
          $('#tt').edatagrid({
           	url:"/umRetentConfig/getListPage?channel="+$('#channel').val()+"&appInfoId=" +$('#appInfoId').val(),
            onClickRow: function(index){
            	 if($('#channel').val()==''&&$('#appInfoId').val()==''){return};
                 if(index!=editIndex){
                     editIndex = index;
                  }
             },
             onLoadSuccess:function(data){
             	$(this).datagrid('enableDnd');
             	retentDayArray=[];

             	if(data.rows.length==0){
             		if($('#channel').val()==''&&$('#appInfoId').val()==''){
             			 $('#tt').datagrid({
 	                        url:'',
 	                        data:''
             			 }); 
             		}else{
                   	 var data1 = [
                	              {"retentDay": "1","referenceRate": "68.4",'retentRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "2","referenceRate": "58.7",'retentRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "3","referenceRate": "43.8",'retentRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "4","referenceRate": "39.4",'retentRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "5","referenceRate": "35.5",'retentRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "6","referenceRate": "31.9",'retentRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "7","referenceRate": "30.8",'retentRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "8","referenceRate": "24.6",'retentRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "9","referenceRate": "22.2",'retentRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "10","referenceRate": "20.3",'retentRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "11","referenceRate": "18.1",'retentRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "12","referenceRate": "17.2",'retentRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "13","referenceRate": "13.8",'retentRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "14","referenceRate": "12.4",'retentRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "15","referenceRate": "12.1",'retentRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "16","referenceRate": "7.6",'retentRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "17","referenceRate": "5.2",'retentRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "18","referenceRate": "4.4",'retentRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "19","referenceRate": "4.1",'retentRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "20","referenceRate": "3.9",'retentRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "21","referenceRate": "3.8",'retentRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "22","referenceRate": "2.8",'retentRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "23","referenceRate": "2.4",'retentRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "24","referenceRate": "2.4",'retentRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "25","referenceRate": "1.2",'retentRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "26","referenceRate": "0.4",'retentRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "27","referenceRate": "0.4",'retentRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "28","referenceRate": "0.2",'retentRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "29","referenceRate": "0.2",'retentRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "30","referenceRate": "0.2",'retentRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "31","referenceRate": "68.4",'retentRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "32","referenceRate": "58.7",'retentRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "33","referenceRate": "43.8",'retentRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "34","referenceRate": "39.4",'retentRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "35","referenceRate": "35.5",'retentRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "36","referenceRate": "31.9",'retentRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "37","referenceRate": "30.8",'retentRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "38","referenceRate": "24.6",'retentRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "39","referenceRate": "22.2",'retentRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "40","referenceRate": "68.4",'retentRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "41","referenceRate": "68.4",'retentRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "42","referenceRate": "58.7",'retentRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "43","referenceRate": "43.8",'retentRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "44","referenceRate": "39.4",'retentRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "45","referenceRate": "35.5",'retentRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "46","referenceRate": "31.9",'retentRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "47","referenceRate": "30.8",'retentRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "48","referenceRate": "24.6",'retentRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "49","referenceRate": "22.2",'retentRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "50","referenceRate": "68.4",'retentRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "51","referenceRate": "68.4",'retentRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "52","referenceRate": "58.7",'retentRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "53","referenceRate": "43.8",'retentRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "54","referenceRate": "39.4",'retentRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "55","referenceRate": "35.5",'retentRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "56","referenceRate": "31.9",'retentRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "57","referenceRate": "30.8",'retentRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "58","referenceRate": "24.6",'retentRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "59","referenceRate": "22.2",'retentRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "60","referenceRate": "68.4",'retentRate':'','exetimes':'1','priority':'0'}
                	          ];
             			$('#tt').datagrid({
 	                        url:'',
 	                        data:data1
             			 }); 
             			
             		}
            	}else{
                  	$.each(data.rows,function(index,mod){
                		retentDayArray.push(mod.retentDay)
                	});
            	}
             },
             onBeforeSave:function(index){
            	 var retentDayVal=$("td[field='retentDay'] input").val();
            	 var retentRateVal=$("td[field='retentRate'] input").val();
            	 if(retentDayVal==''){
            		 alert("请输入留存天数");
            		 return false; 
            	 }
            	 if(retentRateVal==''){
            		 alert("请输入留存比例");
            		 return false; 
            	 }
             }
          });
         //查询
         function doSearch(){
//          	$('#tt').edatagrid({
//          		url:"/umRetentConfig/retentList?channel="+$('#channel').val()});
          	var channel=$('#channel').val();
        	var appInfoId=$('#appInfoId').val();
        	$('#tt').edatagrid({
        		url:'/umRetentConfig/getListPage',
        		queryParams:{
        			channel:channel,
        			appInfoId:appInfoId
        		}
        	});
//        	$('#tt').datagrid('unselectAll');
         }
         //添加
         function addRow(){
         	var channel=$('#channel').val();
         	if(channel==''){return;}
         	var appInfoId=$('#appInfoId').val();
         	if(appInfoId==''){return;}
         	var apkName=$('#apkName').html();
//         	var file='/resources/js/easyui/datagrid-dnd.js';
         	$('#tt').edatagrid('appendRow', {
         		channel:channel,    
         		appInfoId:appInfoId,    
         		apkName:apkName,    
                retentDay:'',
                exetimes:'1',
                priority:'0'
            });
            $('#tt').datagrid('enableDnd');
         }

          //保存
		function saveRow(){
		    var channel=$('#channel').val();
         	if(channel==''){return;}
         	 var appInfoId=$('#appInfoId').val();
          	if(appInfoId==''){return;}
          	 var apkName=$('#apkName').html();
          	if(apkName==''){return;}
            var newRow=[];
            var arrayLen=0;
            $('#tt').edatagrid('saveRow');
            var initRow=$("#tt").datagrid('getRows');
 		  	$.each(initRow,function(index,mod){
		  		if(mod.retentRate==''||mod.exetimes==''||
		  				mod.retentDay==''||mod.exetimes==0||mod.retentRate==0){
			  		
		  		}else{
		  			var	array={};
			  		array={retentRate:mod.retentRate,
			  				retentDay:mod.retentDay,
			  				exetimes:mod.exetimes,
			  				channel:channel,
			  				appInfoId:appInfoId,
			  				apkName:apkName,
			  				priority:mod.priority};
			  		newRow.push(array);
			  		arrayLen=newRow.length;
		  		}
		  		
		  	});
		  
		  	$.ajax({
		  		url:'/umRetentConfig/save',
		  		type:'post',
		  		dataType:"json",
		  		data:JSON.stringify(newRow),
		  		contentType:'application/json',
		  		success:function(){
		  			jQuery.messager.alert('提示:','成功保存'+arrayLen+'条数据!'); 
		  			doSearch();
		  		}
		  	});
            
        }
        //删除
        function remove(){
        	var rows = $('#tt').edatagrid('getChecked');
		  	var arr = [];
		  	for (var i=0;i<rows.length;i++) {
		  		arr.push(rows[i].id)
		  	}
	    	var ids = arr.join(",");
	   		  $.post('/umRetentConfig/delete',{ids:ids}, function(data) {
	   		  	if (data.return_code == '1') {
	   				jQuery.messager.alert('提示:','删除成功!'); 
	   				$("#tt").datagrid('reload');
	   				$('#tt').datagrid('clearSelections');
	   			} else {
	   				$.messager.alert(market.content.title, data.return_msg);
	   			}
	   		  });
        }
        //全选
        function selectAll(){
        	 $('#tt').datagrid('selectAll');
        }
        //输入框限制为数字
		$(document).on("keyup afterpaste","td[field='retentDay'] input","td[field='exetimes'] input",function(){
			this.value=this.value.replace(/\D/g,'');
		})
		//占比输入框限制，最大为100且只最多能有两位小数点 
		$(document).on("keyup afterpaste","td[field='retentRate'] input",function(e){
				 this.value = this.value.replace(/[^\d.]/g,"");  //清除“数字”和“.”以外的字符   
				 this.value = this.value.replace(/\.{2,}/g,"."); //只保留第一个. 清除多余的   
				 this.value = this.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");  
				 this.value = this.value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3');//只能输入两个小数   
				 if(this.value.indexOf(".")< 0 && this.value !=""){//以上已经过滤，此处控制的是如果没有小数点，首位不能为类似于 01、02的金额  
					 this.value= parseFloat(this.value);  
				 }  
				 if(this.value>100){
					 this.value = 100;
				 }
		})
		
		$(document).on('blur', '.datagrid-view td[field=retentDay] input', function(){
			var inputVal=this.value;
			$.each(retentDayArray,function(index,mod){
				if(mod==inputVal){
					$(this).val('');
					jQuery.messager.alert('提示:','留存天数不能重复!');	
				}
			});
		});
  
		function selectApp(){
			$('#tbAppInfo').datagrid({
				url:'/umAppInfo/getListPage'
			});
			
			$('#selectWin').window('open');
		}

		function onDblClickRow(rowIndex, rowData){
			var record = $('#tbAppInfo').datagrid('getSelected');
			if(record==null||record==''){
				$.messager.alert("提示", "请先选择一条记录");
				return;
			}
			$('#appInfoId').val(record.id);
			$('#apkName').html(record.apkName);
			$('#selectWin').window('close');
		}

		function doSearchApp(){
			var appName=$('#appName').val();
			$('#tbAppInfo').datagrid({
				url:'/umAppInfo/getListPage',
				queryParams:{
					apkName:appName,
				}
			});
			$('#tbAppInfo').datagrid('unselectAll');
		}

		